/*
 * @Author: Tendo 
 * @Date: 2021-08-28 23:22:48 
 * @param {number[]} nums
 * @return {res[]}
 */

const sortedSquares = (nums) => {
    let res =  new Array(nums.length),
        left = 0,
        right = nums.length - 1,
        index = res.length-1
        
    while (left <= right) {
        const l = nums[left] * nums[left],
              r = nums[right] * nums[right]
        if (l < r) {
            res[index--] = r
            right--
        } else {
            res[index--] = l
            left++
        }
    }
    return res
}
